﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineStore.Bll;
using OnlineStore.Dal;

namespace OnlineStore.Gui
{
    public partial class Account : System.Web.UI.Page
    {
        bizHistoryCart _bizHistoryCart = new bizHistoryCart();
        int page_Now = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
                Response.Redirect("/",true);
            else
            {
                HL_tab_login.NavigateUrl = "/gui/Account.aspx";
                HL_tab_login.Text = ((tbCustomer)Session["user"]).Username;
                HL_tab_Logout.Visible = true;
            }
            ListCartRight.DataSource = (List<bizCart>)Session["cart"];
            ListCartRight.DataBind();
            lb_Sum.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
            lb_Sum_product.Text = String.Format("{0:0,0 VNĐ}", bizCart.SumAllList((List<bizCart>)Session["cart"]));
            if (page_Now == 0)
                Load_Data();
        }

        protected void listHistoryCart_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            page_Now = e.NewPageIndex;
            Load_Data();
        }
        public void Load_Data()
        {
            listHistoryCart.PageIndex = page_Now;
            listHistoryCart.DataSource = _bizHistoryCart.getHistoryCart((tbCustomer)Session["user"]);
            listHistoryCart.DataBind();
        }
    }
}